<?php
/**
 * Created by PhpStorm.
 * User: kcj
 * Date: 2017/6/19
 * Time: 11:11
 */

namespace app\index\controller;

use think\Controller;

class Record extends Controller
{
    function getRecords($uid)
    {
        $where = '';
        for ($i = 1; $i <= 8; ++$i) {
            $where .= "openid$i" . "='$uid' or ";
        }
        $where = substr($where, 0, strlen($where) - 3);
        $list = db('records')->where($where)->order('id', 'desc')->select();
        Gateway::$registerAddress = GATEWAYADDRESS;
        $json = array("type" => "Records.info", 'data' => $list);
        Gateway::sendToUid($uid, json_encode($json));
    }

    function showRecords($sid)
    {
        $record = db('records')->where("id=$sid")->find();
        $users=[];
        for($i = 1;$i<=8;++$i)
        {
            if (isset($record["openid$i"]) && !empty($record["openid$i"])) {
                $users[$i]['name'] = $record["name$i"];
                $users[$i]['headerurl'] = $record["headerurl$i"];
                $users[$i]['scores'] = $record["scores$i"];
            }
        }
        $this->assign('users',$users);
        $this->assign('time',$record['time']);
        $this->assign("round",$record['roomround']);
        $this->assign('type',$record['roomtype']);
        return view('/records');
    }
}